﻿using System;
using System.Collections.Generic;
using System.Text;
using Ecreate.Model;
using Ecreate.Data;
namespace Ecreate.Business
{
    public class InfoDtlService
    {
        public IList<t_info_dtl> getAllInfo()
        {
            return FactoryDBEngine.SqlMapper().QueryForList<t_info_dtl>("t_info_dtl_SelectAll", null);
        }


        public WebResult<t_info_dtl> getInfoByID(int id)
        {
            WebResult<t_info_dtl> result = new WebResult<t_info_dtl>();
            t_info_dtl model = FactoryDBEngine.SqlMapper().QueryForObject<t_info_dtl>("t_info_dtl_Select", id);
            if (model == null)
            {
                result.ResultObject = model;
                result.Success = false;
                result.Message = "查询失败";
            }
            else
            {
                result.ResultObject = model;
                result.Success = true;
                result.Message = "查询成功";

            }
            return result;
        }


        public WebResult<t_info_dtl> Insert(t_info_dtl model)
        {
            WebResult<t_info_dtl> result = new WebResult<t_info_dtl>();
            try
            {
                FactoryDBEngine.SqlMapper().QueryForObject<t_info_dtl>("t_info_dtl_Insert", model);
                result.ResultObject = model;
                result.Success = true;
                result.Message = "插入数据成功";
            }
            catch
            {
                result.ResultObject = model;
                result.Success = false;
                result.Message = "插入数据失败";

            }
            return result;
        }

        public WebResult<t_info_dtl> Delete(t_info_dtl model)
        {
            WebResult<t_info_dtl> result = new WebResult<t_info_dtl>();
            try
            {
                FactoryDBEngine.SqlMapper().Delete("t_info_dtl_Delete", model);
                result.ResultObject = model;
                result.Success = true;
                result.Message = "删除数据成功";
            }
            catch
            {
                result.ResultObject = model;
                result.Success = false;
                result.Message = "删除数据失败";

            }
            return result;
        }


        public WebResult<t_info_dtl> Update(t_info_dtl model)
        {
            WebResult<t_info_dtl> result = new WebResult<t_info_dtl>();
            try
            {
                FactoryDBEngine.SqlMapper().Update("t_info_dtl_Update", model);
                result.ResultObject = model;
                result.Success = true;
                result.Message = "修改数据成功";
            }
            catch
            {
                result.ResultObject = model;
                result.Success = false;
                result.Message = "修改数据失败";

            }
            return result;
        }
    }
}
